<template>
  <div class="detail">
    <!-- 认购收益详情 -->
    <div class="box mb-15">
      <div class="flex flex-rc">
        <div class="title">{{ $t('认购收益详情') }}</div>
      </div>

      <div v-if="records1.length">
        <ul class="list list--50">
          <li
            class="list__item container bcl-mask mb-15"
            v-for="(v, i) in records1"
            :key="i"
          >
            <div class="item">
              <span class="label">{{ $t('总认购收益额') }}</span>
              <span class="value">{{ v.amount_all }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('获取收益倍数') }}</span>
              <span class="value">{{ v.amount_times }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('退场额') }}</span>
              <span class="value">{{ v.amount_exit }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('日化收益率') }}(%)</span>
              <span class="value">{{ (v.rate_year / 365).toFixed(2) }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('总收益') }}</span>
              <span class="value">{{ v.interest }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('用户收益') }}</span>
              <span class="value">{{ v.profit_pr }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('客户分红') }}</span>
              <span class="value">{{ v.agent_bonus }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('团队奖励') }}</span>
              <span class="value">{{ v.team_rewards }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('上阶段期次') }}</span>
              <span class="value">{{ v.stage_batch }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('更新时间') }}</span>
              <span class="value">{{ formatDateTime(v.update_time) }}</span>
            </div>
          </li>
        </ul>

        <!-- 分页 -->
        <van-pagination
          mode="simple"
          :prev-text="$t('上一页')"
          :next-text="$t('下一页')"
          :total-items="total1"
          :items-per-page="size1"
          @change="getRecords1"
          v-model="page1"
        ></van-pagination>
      </div>

      <van-empty :description="$t('暂无数据')" v-else></van-empty>
    </div>

    <!-- 认购收益订单 -->
    <div class="box">
      <div class="flex flex-rc">
        <div class="title">{{ $t('认购收益订单') }}</div>
      </div>

      <div v-if="records2.length">
        <ul class="list list--50">
          <li
            class="list__item container bcl-mask mb-15"
            v-for="(v, i) in records2"
            :key="i"
          >
            <div class="item">
              <span class="label">{{ $t('金额') }}</span>
              <span class="value">{{ v.order_amount || 0 }} USDT</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('状态') }}</span>
              <span class="value">{{ v.status }}</span>
            </div>
            <div class="item">
              <span class="label">{{ $t('时间') }}</span>
              <span class="value">{{ formatDateTime(v.create_time) }}</span>
            </div>
          </li>
        </ul>

        <!-- 分页 -->
        <van-pagination
          mode="simple"
          :prev-text="$t('上一页')"
          :next-text="$t('下一页')"
          :total-items="total2"
          :items-per-page="size2"
          @change="getRecords2"
          v-model="page2"
        ></van-pagination>
      </div>

      <van-empty :description="$t('暂无数据')" v-else></van-empty>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { formatDateTime } from 'js/utils'
import apis from 'js/apis'

// 认购收益详情
const records1 = ref([])
const page1 = ref(1)
const size1 = ref(2)
const total1 = ref(0)

// 认购收益订单
const records2 = ref([])
const page2 = ref(1)
const size2 = ref(5)
const total2 = ref(0)

getRecords1()
getRecords2()

// 获取认购收益详情
async function getRecords1() {
  const params = {
    page: page1.value,
    limit: size1.value,
  }

  const { code, data } = await apis.pledge.getDetails(params)

  if (code === 1) {
    let records = data.data || []
    records = records.filter((v) => v.contract_status == 1)
    records1.value = records
    total1.value = data.count || 0
  }
}

// 获取认购收益订单
async function getRecords2() {
  const params = {
    page: page2.value,
    limit: size2.value,
  }

  const { code, data } = await apis.pledge.getOrders(params)

  if (code === 1) {
    records2.value = data.data || []
    total2.value = data.count || 0
  }
}
</script>

<style lang="scss" scoped></style>
